package xin.exec.executor.config;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;

import java.lang.reflect.Method;

/**
 * <pre>
 * 自定义异常处理句柄
 * </pre>
 *
 * @author lixin_ma@outlook.com
 * @version 1.0
 * @since 2019/8/12
 */
@Slf4j
public class MyUncaughtExceptionHandler implements AsyncUncaughtExceptionHandler {
	@Override
	public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
		log.error("Unexpected error occurred invoking async method {} , message:{}",
				method.getName(),
				throwable.getMessage());
		if(objects != null && objects.length>0){
			String msg = "";
			for (int i=0;i<objects.length;i++) {
				if(i==0)
					msg = msg + JSONObject.toJSONString(objects[i]);
				else
					msg = msg + "," + JSONObject.toJSONString(objects[i]);
			}
			log.error("Parameter value : {} ",msg);
		}
	}
}
